package com.jxnu.duewang.zmly.zmly.fragment;


import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;

import com.jxnu.duewang.zmly.R;
import com.jxnu.duewang.zmly.zmly.adapter.MyAdapter;

import java.util.ArrayList;
import java.util.List;

import liyuxian.fragment.fragment.HistoryFragment;
import liyuxian.fragment.fragment.Rec1Fragment;
import liyuxian.fragment.fragment.SubFragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class SubscribeFragment extends Fragment {


    private ViewPager viewPager;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;
    private List<Fragment> list;
    private List<String> str;
    private HistoryFragment historyFragment;
    private Rec1Fragment recommendFragment;
    private SubFragment subFragment;
    private TableLayout tab;
    private TabLayout tabs;

    public SubscribeFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_subscribe, container, false);
        viewPager = (ViewPager) view.findViewById(R.id.view_pager);
        tabs = (TabLayout)view.findViewById(R.id.tab_layout);
        initdata();
        return  view;
    }



    private void initdata() {
        //初始化
        list = new ArrayList<>();
        historyFragment = new HistoryFragment();
        recommendFragment = new Rec1Fragment();
        subFragment = new SubFragment();

        list.add(recommendFragment);
        list.add(subFragment);
        list.add(historyFragment);
        str = new ArrayList<>();
        str.add("推荐");
        str.add("订阅");
        str.add("历史");
        viewPager.setAdapter(new MyAdapter(getChildFragmentManager(),list,str));
        tabs.setupWithViewPager(viewPager);
    }
}
